| Conditions | 1 |
| Paths | 12 |
| Total Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import path from 'path' |
||
| 142 | export function getFilesMerged(files) { |
||
| 143 | var merged = {} |
||
| 144 | var arMerged = [] |
||
| 145 | |||
| 146 | Array.prototype.forEach.call(files, (file) => { |
||
| 147 | var cleanFilePath = file.cleanFilePath |
||
| 148 | |||
| 149 | var fileStatusIsPublish = cmsData.fileAttr.get(file.cleanPath) |
||
| 150 | if(typeof fileStatusIsPublish.s !== 'undefined' && fileStatusIsPublish.s !== null && file.abe_meta.status === 'publish') { |
||
| 151 | file.abe_meta.status = 'draft' |
||
| 152 | } |
||
| 153 | |||
| 154 | file.html = path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`)) |
||
| 155 | if (file.abe_meta.status === 'publish') { |
||
| 156 | file.htmlPath = path.join(config.root, config.publish.url, path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))) |
||
| 157 | }else { |
||
| 158 | file.htmlPath = path.join(config.root, config.draft.url, path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))) |
||
| 159 | } |
||
| 160 | |||
| 161 | if(typeof merged[cleanFilePath] === 'undefined' || merged[cleanFilePath] === null) { |
||
| 162 | merged[cleanFilePath] = { |
||
| 163 | name: cmsData.fileAttr.delete(file.name) |
||
| 164 | , path: cmsData.fileAttr.delete(file.path) |
||
| 165 | , html: cmsData.fileAttr.delete(path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))) |
||
| 166 | , htmlPath: path.join(config.root, config.publish.url, path.join('/', cmsData.fileAttr.delete(file.filePath.replace(/\.json/, `.${config.files.templates.extension}`)))) |
||
| 167 | , cleanPathName: file.cleanPathName |
||
| 168 | , cleanPath: file.cleanPath |
||
| 169 | , cleanName: file.cleanName |
||
| 170 | , cleanNameNoExt: file.cleanNameNoExt |
||
| 171 | , cleanFilePath: file.cleanFilePath |
||
| 172 | , filePath: cmsData.fileAttr.delete(file.filePath) |
||
| 173 | , revisions: [] |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | merged[cleanFilePath].revisions.push(JSON.parse(JSON.stringify(file))) |
||
| 178 | }) |
||
| 179 | |||
| 180 | // return merged |
||
| 181 | Array.prototype.forEach.call(Object.keys(merged), (key) => { |
||
| 182 | var revisions = merged[key].revisions |
||
| 183 | revisions.sort(FileParser.predicatBy('date', -1)) |
||
| 184 | if(typeof revisions[0] !== 'undefined' && revisions[0] !== null) { |
||
| 185 | merged[key].date = revisions[0].date |
||
| 186 | } |
||
| 187 | |||
| 188 | Array.prototype.forEach.call(revisions, (revision) => { |
||
| 189 | |||
| 190 | var status = revision.abe_meta.status |
||
| 191 | |||
| 192 | if (status === 'publish') { |
||
| 193 | merged[key][status] = revision |
||
| 194 | }else { |
||
| 195 | merged[key][status] = {} |
||
| 196 | } |
||
| 197 | merged[key][status].path = revision.path |
||
| 198 | merged[key][status].html = revision.html |
||
| 199 | merged[key][status].htmlPath = revision.htmlPath |
||
| 200 | merged[key][status].date = new Date(revision.date) |
||
| 201 | merged[key][status].link = revision.abe_meta.link |
||
| 202 | }) |
||
| 203 | |||
| 204 | merged[key].revisions = revisions |
||
| 205 | |||
| 206 | merged[key].date = revisions[0].date |
||
| 207 | merged[key].cleanDate = revisions[0].cleanDate |
||
| 208 | merged[key].duration = revisions[0].duration |
||
| 209 | merged[key].abe_meta = revisions[0].abe_meta |
||
| 210 | |||
| 211 | arMerged.push(merged[key]) |
||
| 212 | }) |
||
| 213 | |||
| 214 | return arMerged |
||
| 215 | } |
||
| 216 | |||
| 235 | } |